<template>
  <div id="modiifyInformation">
    <div class="inf_form">
      <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名：" prop="username">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码：" prop="password">
          <el-button type="primary" @click="alterPw" class="form_password">修改密码</el-button>
        </el-form-item>
        <el-form-item label="头像：" prop="avatar">
          <div class="upload" @click="alterCA">
            <el-avatar :size="50" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
          </div>
        </el-form-item>
        <el-form-item label="手机号：" prop="telephone">
          <el-input v-model="form.telephone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱：" prop="email">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
        <el-form-item class="form_button">
          <el-button type="primary" @click="submitForm('ruleForm')" class="form_alert">修改</el-button>
        </el-form-item>
      </el-form>
    </div>
    <ChangePassword v-if="openCP" @closeCP="closeCP"></ChangePassword>
    <ChangeAvatar v-if="openCA" @closeCA="closeCA"></ChangeAvatar>
  </div>
</template>

<script>
import changePassword from "@/components/changePassword";
import changeAvatar from "@/components/changeAvatar";

export default {
  name: "ModiifyInformation",
  components: {
    ChangePassword: changePassword,
    ChangeAvatar:changeAvatar
  },
  data() {
    return {
      form: {
        username: '',
        telephone: '',
        email: ''
      },
      openCP: false,
      openCA: false,
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    alterPw() {
      this.openCP = true
    },
    closeCP() {
      this.openCP = false
    },
    alterCA() {
      this.openCA = true
    },
    closeCA() {
      this.openCA = false
    }
  }
}
</script>

<style lang="less" scoped>
#modiifyInformation {
  width: 100%;
  height: 100%;

  .inf_form {
    display: flex;
    justify-content: center;

    .el-form {
      width: 65%;

      .form_button {
        display: flex;
        justify-content: center;
      }

      .form_password {
        background-color: black;
        border-color: black;
      }

      .form_alert {
        width: 120px;
        background-color: black;
        border-color: black;
      }

      .upload {
        cursor: pointer;
      }
    }
  }
}
</style>
